BUILD_TIME := $(shell date +"%Y-%m-%d %H:%M:%S")
GIT_COMMIT := $(shell git show -s --pretty=format:%h)
GO_VERSION := $(shell go version)
BUILD_PATH := './build/bin/platon-tools'

linux:
	@echo "start build platOn tools service for linux..."
	GOOS=linux GOARCH=amd64 go build -v -ldflags "-w -s -X platon-tools/go-service/version.BuildNumber=${GIT_COMMIT} -X 'platon-tools/go-service/version.BuildTime=${BUILD_TIME}' -X 'platon-tools/go-service/version.GoVersion=${GO_VERSION}'" -o $(BUILD_PATH)-linux-amd64  .
	chmod +x $(BUILD_PATH)-linux-amd64

macos:
	@echo "start build platOn tools service for macos..."
	GOOS=darwin GOARCH=amd64 go build -v -ldflags "-w -s -X platon-tools/go-service/version.BuildNumber=${GIT_COMMIT} -X 'platon-tools/go-service/version.BuildTime=${BUILD_TIME}' -X 'platon-tools/go-service/version.GoVersion=${GO_VERSION}'" -o $(BUILD_PATH)-darwin-amd64  .
	chmod +x $(BUILD_PATH)-darwin-amd64

win:
	@echo "start build platOn tools service for windows..."
	GOOS=windows GOARCH=amd64 go build -v -ldflags "-w -s -X platon-tools/go-service/version.BuildNumber=${GIT_COMMIT} -X 'platon-tools/go-service/version.BuildTime=${BUILD_TIME}' -X 'platon-tools/go-service/version.GoVersion=${GO_VERSION}'" -o $(BUILD_PATH)-windows-amd64.exe  .
	#chmod +x $(BUILD_PATH)-windows-amd64

docker:
	@echo "start build platOn tools service for docker..."
	docker build -f ./Dockerfile -t platon-tools:v11.1 .

monitor-linux:
	@echo "start build platOn tools service for linux..."
	GOOS=linux GOARCH=amd64 go build -v -ldflags "-w -s -X platon-tools/go-service/version.BuildNumber=${GIT_COMMIT} -X 'platon-tools/go-service/version.BuildTime=${BUILD_TIME}' -X 'platon-tools/go-service/version.GoVersion=${GO_VERSION}'" -o $(BUILD_PATH)-monitor-linux-amd64  ./setups/monitor
	chmod +x $(BUILD_PATH)-monitor-linux-amd64

all: macos linux win